package com.example.leetdemo.finash;

public class Solution3115 {

    public int maximumPrimeDifference(int[] nums) {
        int l = nums.length - 1, p = nums.length - 1;
        for (int i = 0; i < nums.length; i++) {
            if (isPre(nums[i])) {
                if (l == nums.length - 1) {
                    l = i;
                }
                p = i;
            }
        }
        return p - l;
    }

    private boolean isPre(int num) {
        if (num == 1) {
            return false;
        }
        if (num < 4) {
            return true;
        }
        for (int i = 2; i < num / 2 + 1; i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }

}
